<?php

/**
 * @author @author Samrat Khan & Sadik Sarfaraz - Apr 16, 2013
 */
/**
 * 
 * @param string $db Common database connection string parameter
 * @return string $CI returns status name from returnstatus table
 */
function getReturningStatus($db) {
    $query = "SELECT status_id, statusname FROM faultystatus";
        try {
            $stmt = $db->prepare($query);
            $stmt->execute();
        } catch (PDOException $ex) {
            die("Failed to run query: " . $ex->getMessage());
        }
        $rows = $stmt->fetchAll();

        foreach($rows as $row1) {
            $CI.="<option value='{$row1["status_id"]}'>";
                $CI.=$row1['statusname'];
            $CI.="</option>";
            $CI++;
        }
        return $CI;
}

function pickReturnStatus($cus_id, $db) {
    $query = "SELECT so.response_type_id, so.stockout_id, so.requestnumber, so.serialno, so.productid, so.siteid, so.receivedtime, so.out_quantity, so.uom, rn.note_id, rn.stockout_id, rn.backstatus, rn.inserteddate, rn.pickuprequestdate 
        FROM stockout so, returnnote rn 
        WHERE so.stockout_id = rn.stockout_id AND rn.backstatus = '0' AND rn.cus_id = '$cus_id' AND so.response_type_id !=11 ORDER BY rn.note_id DESC";
    // var_dump($query);
    // SELECT so.stockout_id, so.requestnumber, so.serialno, so.productid, so.siteid, so.receivedtime, so.out_quantity, so.uom, rn.note_id, rn.stockout_id, rn.backstatus, rn.inserteddate 
    // FROM stockout so, returnnote rn 
    // WHERE so.stockout_id = rn.stockout_id AND rn.backstatus = '0' AND rn.cus_id = '$cus_id'
    try {
        $stmt = $db->prepare($query);
        $stmt->execute();
    } catch (PDOException $ex) {
        die("Failed to run query: " . $ex->getMessage());
    }
    $rows = $stmt->fetchAll();
    return $rows;
}
?>
